package com.usian.wemedia.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.usian.apis.wemedia.WmUserControllerapi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.pojos.WmUser;
import com.usian.utils.threadlocal.WmThreadLocalUtils;
import com.usian.wemedia.service.WmUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/auth")
public class WmUserController implements WmUserControllerapi {
  @Autowired
  private WmUserService userService;
    @Override
    @PostMapping("/save")
    public ResponseResult save(@RequestBody WmUser wmUser) {
        userService.save(wmUser);
        return null;
    }

    @Override
    @GetMapping("/findByName/{name}")
    public WmUser findByName(@PathVariable("name") String name) {
        WmUser user = WmThreadLocalUtils.getUser();
        System.out.println(user.getId());
        List<WmUser> list = userService.list(new LambdaQueryWrapper<WmUser>().eq(WmUser::getName,name));
        for (WmUser wmUser : list) {
            return  wmUser;
        }
        return null;
    }
}
